#include "precompiled.h"
#include "Geometry_Pool.h"
#include "Model.h"

// Define our unordered map type.
typedef std::tr1::unordered_map<std::string, Model> umap_id;

Geometry_Pool::Geometry_Pool(void)
{
	printf("Crated geometry pool...\n");
}


Geometry_Pool::~Geometry_Pool(void)
{

}

bool Geometry_Pool::add_model(std::string key, Model &value){

	// Check if our key already exists.
	if( isPooled( key ) )
		return false;

	model_pool.insert( std::make_pair(key, value)  );
	
	printf("pooled model [%s]\n",key.c_str());
	return true;
}

 Model* Geometry_Pool::get_modelValue(std::string key){

	// Check if our key exists.
	 if( !isPooled( key ) )
		return 0;//false;

	// Find the position of the value and assign it.
	umap_id::iterator it = model_pool.find( key );
	return &it->second;
}

 bool Geometry_Pool::isPooled( std::string key ){
	 // Check if our key already exists.
	 umap_id::iterator it = model_pool.find( key );
	 if( it == model_pool.end() )
		 return false;

	 return true;
 }

 void Geometry_Pool::Clear_Pool(){

	 delete_pool_vertices();
	 model_pool.clear();
 }

 void Geometry_Pool::delete_pool_vertices(){
	 for( umap_id::iterator it = model_pool.begin();
			it != model_pool.end();
			++it){
				printf("Deleting vertices of model: %s\n", it->first);
				it->second.Delete_Vertices();
	 }
 }